/**
 * 功能描述 总表格触发事件
 */
define(function (require, exports, module) {
	var store = require("store");
	var activeUser = store.get("user");
	var Dialog=require("dialog");
	var aw = require("ajaxwrapper");
	var Form = require("form");
	
    module.exports = {
    	gridTk : function(data, widget){
			var remarkForm3 =new Form({
				parentNode:".J-form-dialog",
				autoRender : false,
        		model:{
					id:"remarkForm3",
					defaultButton:false,
					items:[{
						name : "cardNo",
						label : "卡号",
						defaultValue : data.cardNo,
						readonly : true,
					},{
						name  : "travelContract.member.personalInfo.name",
						label : "会员",
						defaultValue : data.travelContract.member.personalInfo.name,
						readonly : true,
					},{
						name  : "price",
						label : "应退余额(元)",
						defaultValue : data.balance,
						validate : ["required"],
						exValidate: function(value) {
		                	var reg = /^([1-9][\d]{0,7}|0)(\.[\d]{1,2})?$/;
                            if (!reg.test(value) || data.balance<value) {
                                return "金额格式不正确或者大于余额！";
                            } else {
                            	var form = widget.get("remarkForm3");
								form.setValue("nowmoney",form.getValue("price")*0.8);
                                return true;
                            }
                        }, 
					},{
						name  : "nowmoney",
						label : "折合(元)",
						defaultValue : parseInt(data.balance)*0.8,
						readonly : true,
					},{
						name  : "operator",
						label : "经办人",
						defaultValue : activeUser.name,
						readonly : true,
					},{
						name  : "operateDate",
						label : "办理日期",
						defaultValue : moment(new Date()).format("YYYY-MM-DD"),
						type : "date",
						readonly : true,
					},{
						name  : "remarkDetail",
						label : "备注"
					}]
				 }
			});
			widget.set("remarkForm3",remarkForm3);
			Dialog.showComponent(remarkForm3,{
				defaultButton:false,
				title: "退卡",
				buttons :[{
					id:"save",
					text:"确定",
						className:"btn-isave",
					handler:function(){
						if(remarkForm3.valid()){
							var FormData = remarkForm3.getData();
							var saveData = {};
							saveData.price = FormData.price;
							saveData.operateDate = FormData.operateDate;
							saveData.remarkDetail = FormData.remarkDetail;
							saveData.operator = activeUser.pkUser;
							saveData.welfareConsumptionCoupon = data.pkWelfarecc;
							saveData.servicePoint = widget.get("subnav") .getValue("servicePoint") 
							aw.saveOrUpdate("api/welfareconsumptioncoupondetail/returncard",aw.customParam(saveData),function(saveData){
								Dialog.close();
			          			widget.get("grid").refresh();
			       			});
						};
					}
				},{
					id:"close",
					text:"取消",
					handler:function(){
						Dialog.close();
					}
				}]
			});
	},
    };
});
